<template>
  <div class="app-container">
    <h3>订单列表</h3>
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="orderQuery.orderNo" placeholder="订单号"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="orderQuery.courseTitle" placeholder="课程名称"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="orderQuery.nickname" placeholder="会员昵称"/>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="initOrderList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>

    </el-form>
    <!-- 列表显示-->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (current - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <!--      <el-table-column prop="orderNo" label="订单号"/>-->

      <el-table-column prop="courseTitle" label="课程名称"/>

      <el-table-column label="课程封面">
        <template slot-scope="scope">
          <div class="pic">
            <img :src="scope.row.courseCover" alt="scope.row.title" width="150px" height="100px">
          </div>
        </template>
      </el-table-column>

      <el-table-column prop="nickname" label="用户昵称"/>
      <el-table-column label="订单金额" width="100px">
        <template slot-scope="scope">
          {{scope.row.totalFee}}&nbsp;&nbsp;元
        </template>
      </el-table-column>

      <el-table-column prop="createTime" label="添加时间"/>

      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button type="info" title="详情" size="mini" icon="el-icon-info" @click="getOrderById(scope.row.id)">
          </el-button>
          <!-- <router-link :to="'/cms/banner/update/'+scope.row.id">
             <el-button type="primary" title="修改" size="mini" icon="el-icon-edit"
             ></el-button>
           </router-link>-->
          <el-button type="danger" title="删除" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      :current-page="current"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="initOrderList"
      @size-change="changeLimit"
    />

    <!-- 订单详情表单 -->
    <el-dialog :visible.sync="orderFormVisible" title="订单详情">
      <el-form :model="orderForm" label-width="120px">
        <el-form-item label="订单ID">
          <el-input readonly v-model="orderForm.id"/>
        </el-form-item>
        <el-form-item label="订单号">
          <el-input readonly v-model="orderForm.orderNo"/>
        </el-form-item>
        <el-form-item label="课程ID">
          <el-input readonly v-model="orderForm.courseId"/>
        </el-form-item>
        <el-form-item label="课程标题">
          <el-input readonly v-model="orderForm.courseTitle"/>
        </el-form-item>
        <el-form-item label="课程封面">
          <!--          <el-input v-model="orderForm.courseCover"/>-->
          <el-image :src="orderForm.courseCover" :title="orderForm.courseTitle"
                    style="width: 375px;height: 215px">
          </el-image>
        </el-form-item>
        <el-form-item label="讲师姓名">
          <el-input readonly v-model="orderForm.teacherName"/>
        </el-form-item>
        <el-form-item label="会员ID">
          <el-input readonly v-model="orderForm.memberId"/>
        </el-form-item>
        <el-form-item label="会员昵称">
          <el-input readonly v-model="orderForm.nickname"/>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input readonly v-model="orderForm.mobile"/>
        </el-form-item>
        <el-form-item label="付款金额">
          <el-input readonly v-model="orderForm.totalFee"/>
        </el-form-item>
        <el-form-item label="支付方式">
          <el-input readonly v-model="orderForm.payType===1?'微信':'支付宝'"/>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-input readonly v-model="orderForm.status==1?'未支付':'已支付'"/>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input readonly v-model="orderForm.createTime"/>
        </el-form-item>
        <el-form-item label="更新时间">
          <el-input readonly v-model="orderForm.updateTime"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderFormVisible = false">确&nbsp;&nbsp;定</el-button>
        <!--<el-button type="primary" @click="saveOrUpdate">确 定</el-button>-->
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import order from "@/api/order/order";

  export default {
    name: "list",
    data() {
      return {
        list: [],//订单数据列表
        current: 1,//当前页
        limit: 5,//每页显示记录数
        total: 0,//总记录数
        orderQuery: {},//查询条件
        orderFormVisible: false,//详情窗口是否显示
        orderForm: {},//订单对象
      }
    },
    created() {
      this.initOrderList(1)
    },
    methods: {
      //初始化订单列表
      initOrderList(current = 1) {
        this.current = current
        order.pageOrderList(this.current, this.limit, this.orderQuery)
          .then(response => {
            this.list = response.data.items //获取记录集合
            this.total = response.data.total//获取总记录数
          })
      },
      //根据id查询订单详细信息
      getOrderById(id) {
        order.getOrder(id)
          .then(response => {
            this.orderFormVisible = true
            this.orderForm = response.data.order
          })
      },
      // 当页码发生改变的时候
      changeLimit(limit) {
        console.log(limit)
        this.limit = limit
        this.initOrderList(1)
      },
      //清空
      resetData() {
        //清空查询表单
        this.orderQuery = {}
        //刷新列表
        this.initOrderList(1)
      },
      //删除订单
      removeDataById(id) {
        this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {//点击确认调用
          order.removeOrderById(id)
            .then(response => {
              //提示
              this.$message({
                type: 'success',
                message: response.message
              })
              //刷新列表
              this.initOrderList(1)
            })
            .catch(response => {
              //提示
              this.$message({
                type: 'error',
                message: response.message
              })
              //刷新列表
              this.initOrderList(1)
            })
        })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
      },

    }

  }
</script>

<style scoped>

</style>
